@extends('owner.base')
@section('content')
    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief" style="">
        <ul class="layui-tab-title">
            <li class="layui-this">便捷发送短信</li>
        </ul>
        <div class="layui-card layui-tab-content" style="">
            <div class="layui-card-body layui-tab-item layui-show">

                <div class="layui-form-item">
                    <label for="" class="layui-form-label">选择手机号</label>
                    <div id="dataTable"></div>
                </div>


                <div class="layui-form-item">
                    <label for="" class="layui-form-label">群发内容</label>
                    <div class="layui-input-block">
                            <textarea id="msg" class="layui-textarea" name="description" cols="30" rows="3"
                            ></textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" id="sendMsg" lay-filter="formDemo">发 送</button>
                    </div>
                </div>
                <input type="hidden" id="data-form"></input>
            </div>

        </div>
    </div>

@endsection

@section('script')

    <script>
        layui.use(['layer', 'table', 'form', 'upload'], function () {
            var layer = layui.layer;
            var form = layui.form;
            var table = layui.table;
            var upload = layui.upload;
            //用户表格初始化
            var dataTable = table.render({
                elem: '#dataTable'
                , height: 200
                , url: "{{ route('owner.driver.getdrivermail') }}" //数据接口
                , page: false //开启分页
                , cols: [[ //表头
                    {type: 'radio'},
                    {field: 'title', title: '标签', sort: true}


                ]]
            });

            $("#sendMsg").on('click', function () {
                //判断是否选中
                var ids = []
                var hasCheck = table.checkStatus('dataTable')
                var hasCheckData = hasCheck.data;
                if (hasCheckData.length > 0) {
                    $.each(hasCheckData, function (index, element) {
                        ids.push(element.id);

                    })
                }
                if (ids.length <= 0) {
                    layer.msg("请选择标签", {icon: 5});
                    return false;
                }
                //查询标签下的所有手机号，并发送短信
                $.post('{{route('owner.driver.sendlabel')}}', {
                    'ids': ids,
                    'msg': $("#msg").val()
                }, function (dataforjson) {
                    layer.msg(dataforjson.msg, {icon: 6});
                }, 'json');
            });


        })


    </script>

@endsection()

